package org.raymond.iworks.study.flowable.event;

import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;

import java.util.HashMap;
import java.util.Map;

public class TimerEventProcess {
    private static RuntimeService runtimeService;
    private static TaskService taskService;
    private static HistoryService historyService;

    private static TimerEventProcess instance;

    private TimerEventProcess(RuntimeService runtimeService, TaskService taskService, HistoryService historyService){
        this.runtimeService = runtimeService;
        this.taskService = taskService;
        this.historyService = historyService;
    }

    public static synchronized TimerEventProcess instance(RuntimeService runtimeService, TaskService taskService, HistoryService historyService){
        if(instance==null){
            instance = new TimerEventProcess(runtimeService, taskService, historyService);
        }
        return instance;
    }

    public String startProcess(){
        Map<String, Object> variables = new HashMap<>();
        variables.put("EndDate", "2023-05-16T9:05");
        return runtimeService.startProcessInstanceByKey("timer1", variables).getId();
    }
}
